{% extends "base.html" %}

{% block content %}

 <script language=javascript>

function show(id){
	if(document.getElementById("table_foot"+id).style.display=="none"){
		document.getElementById("table_foot"+id).style.display="block";
	}else{
		document.getElementById("table_foot"+id).style.display="none";
	}
}
function showall()
{
   for(var  i=0;i<document.form1.elements.length;i++){  
       var  e=document.form1.elements[i];  
	   if  (e.name  !=  'chkall'){
	   					if (e.name =='tt')
						{
							document.getElementById("table_foot"+e.value).style.display="block";
						}
		}
	}
}
function hideall()
{
   for(var  i=0;i<document.form1.elements.length;i++){  
       var  e=document.form1.elements[i];  
	   if  (e.name  !=  'chkall'){
	   					if (e.name =='tt')
						{
							document.getElementById("table_foot"+e.value).style.display="none";
						}
		}
	}
}
</script>
<script>  
function  CheckAll()  
{  
   for(var  i=0;i<document.form1.elements.length;i++){  
       var  e=document.form1.elements[i];  
       if  (e.name  !=  'chkall'){  
             e.checked  =  document.form1.chkall.checked;
			 }
		else{
				if (document.form1.chkall.checked)
				{
					showall();
				}
				else
				{
					hideall();
				}
			}
   }  //end for
}  
</script> 

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
	<form name='form1' id='form1' action="/testallocation_do/" method='post' >
<table width='80%' class='grid' cellspacing='1' align='center'><tr><td colspan='10' class='title' align="center">distribute Customs</td></tr>

{% if not s_id %}
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Distribution by Program</td>
<td class='even'>
<select name="projects_id">
<option value="0">Plz choose project</option>
  {% for pj in pj %}
<option value="{{pj.id}}">{{pj.name}}</option>
  {% endfor %}
</select>&nbsp;&nbsp;if doesn't choose,will distribute All items customers to sales
</td></tr>
{% endif %}
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Choose sales</td>
<td class='even'>
  {% for sp in sp %}

         {% ifnotequal s_id sp.id %}
                <input type="checkbox" name="sp[{{sp.id}}]" value="1" onclick="show({{sp.id}})" />{{sp.name}} &nbsp;&nbsp;
				<!--传隐藏变量以给JS全先时识别显示全部SALES比例输入框.-->
				<input type="hidden" name="tt" value="{{sp.id}}" />
         {% endifnotequal %}

  {% endfor %}
  <font color="red">{{errormsg}}</font>
</td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'>checkbox option</td>
<td class='even'><INPUT  onclick=CheckAll()  type=checkbox  name=chkall value="1" > select all
</td></tr>
<!-- 显示SALES分得的比例输入框-->
<tr valign='middle' colspan="2" ><td colspan="2">
  {% for sp in sp %}
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="table_foot{{sp.id}}" style="display:none">
<tr valign='middle' align='left' >
<td class='odd' width='25%'>{{sp.name}}</td>
<td class='even' align="left">
<input type="text" name="sprate[{{sp.id}}]" /> %
</td>
</tr>
</table>
  {% endfor %}
</td></tr>

<input type="hidden" name="s_id" value="{{s_id}}" />
<tr valign='middle' align='left'><td class='odd' width='25%'></td>
<td class='even'>&nbsp;<input type='submit' class='button' name='submit'  id='submit' value=' Submit '  />&nbsp;<input type='button' class='button' name='back'  id='reset' value=' Back ' onclick="javascrip:history.back(1)" /></form></td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'>Note:</td>
<td class='even'>
Only allocate the customers who haven't been allocated by average to the sales that you choosed
</td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'></td>

</table>


{% endblock %}
